/***************************************************************************
 创建者：华磊
 开始时间：         : 2020.12.13
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   等待指令属性编辑视窗
*                                                                         *
 ***************************************************************************/
#include "checkbatteryview.h"
#include "ui_checkbatteryview.h"
#include "../../programView/programview.h"


CheckBatteryView::CheckBatteryView(int styleId,QWidget *parent):
    QWidget(parent),
    ui(new Ui::CheckBatteryView)
{
    ui->setupUi(this);
    initialDisplayStyle(styleId);

    ui->batteryLevel_slider->setMaximum(100);
}

void CheckBatteryView::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        ui->forward_Btn->setGeometry(10,350,70,40);
        ui->save_Btn->setGeometry(360,350,70,40);
        break;
    default:
        break;
    }
}

void CheckBatteryView::updateView()
{
    // QString textToShow="";
    //textToShow=QString("%1").arg(batteryElectricQuantity, 0, 'g',4);
    ui->electricQuantiry_lineEdit->setText(batteryElectricQuantity);
    ui->batteryLevel_slider->setValue(batteryElectricQuantity.toInt());
    ui->LBL_lineEdit->setText(batteryLBLIndex);
    ui->note_lineEdit->setText(note);
}

void CheckBatteryView::getInput()
{
    //
<<<<<<< HEAD
    ui->electricQuantiry_lineEdit->text();

=======
>>>>>>> dev
    int batteryLevel = ui->batteryLevel_slider->value();
    batteryElectricQuantity=QString::number(batteryLevel);

    batteryLBLIndex = ui->LBL_lineEdit->text();
    note = ui->note_lineEdit->text();
}
void CheckBatteryView::initData()
{
    note ="";
    //电量 Electric quantity
    batteryElectricQuantity = "0";
    //LBL
    batteryLBLIndex = "";
    checkBatteryInstruction = "";
}

void CheckBatteryView::changeLanguage(int language)
{
    if(1 == language)
    {
        translator.load("/agvwork/AgvHmi/baseBag/hmiProject/language/checkBatteryInstructionView.qm");
        qApp->installTranslator(&translator);
    }
    else
    {
        qApp->removeTranslator(&translator);
    }
    ui->retranslateUi(this);
}

void CheckBatteryView::on_clearNote_Btn_clicked()
{
    ui->note_lineEdit->clear();
    emit clearNote();
}

void CheckBatteryView::on_forward_Btn_clicked()
{
    this->close();
    programView->instructionListFlag = 0;
    programView->editInstructionViewShowOrHide();
}

void CheckBatteryView::on_save_Btn_clicked()
{
    finishedEditInstructionHandle();
}
void CheckBatteryView::finishedEditInstruction_slot()
{
    finishedEditInstructionHandle();
}
void CheckBatteryView::finishedEditInstructionHandle()
{
    getInput();
    emit finishEditInstructionSignal();
    emit saveInstructionSignal(checkBatteryInstruction);
}

void CheckBatteryView::on_batteryLevel_slider_valueChanged(int value)
{
    ui->electricQuantiry_lineEdit->setText(QString::number(value));


}

void CheckBatteryView::on_electricQuantiry_lineEdit_editingFinished()
{
    QString inputBatteryLevel=ui->electricQuantiry_lineEdit->text();
    ui->batteryLevel_slider->setValue(inputBatteryLevel.toInt());
}
